﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SampleWinProject
{
    public partial class frmViewASCII : Form
    {
        public frmViewASCII()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            
            string filename = openFileDialog1.FileName;
            openFileDialog1.Dispose();
            openFileDialog1 = null;
            System.Collections.Generic.SortedList<byte,byte> hash = new SortedList<byte,byte>();
            System.IO.BinaryReader reader = new System.IO.BinaryReader(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            try
            {
                while (true)
                {
                    byte b = reader.ReadByte();
                    if (!hash.ContainsKey(b))
                        hash.Add(b, b);
                    
                }
            }
            catch (System.IO.EndOfStreamException err)
            {

            }
            finally
            {
                reader.Close();
                reader = null;
            }
            richTextBox1.Clear();
            foreach (byte b in hash.Keys)
            {
                richTextBox1.AppendText("ASCII=" + b.ToString() + ",Char=" + (char)b);
                richTextBox1.AppendText("\r\n");
            }

        }

        private void frmViewASCII_Resize(object sender, EventArgs e)
        {
            richTextBox1.Height = this.Height - 80;
        }
    }
}
